<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class ListController extends Controller
{

    //主页提交搜索时触发下以方法
    public function search(){
        return view('Home/list');
    }
    public function sfind($sea){
        //按搜索关键字查询结果
        $sea_list = DB::table('films')
        ->leftjoin('film_atts','films.fid','=','film_atts.fid')
        ->leftjoin('areas','films.area_id','=','areas.area_id')
        ->where('actors','like',"%$sea%")
        ->orWhere('title','like',"%$sea%")
        ->orWhere('intro','like',"%$sea%")
        ->paginate(20);
    
        //按分数最高的往下查询输入结果
        $score = DB::table('films')
        ->leftjoin('film_atts','films.fid','=','film_atts.fid')
        //->leftjoin('areas','films.area_id','=','areas.area_id')
        ->orderBy('score','desc')->paginate(10);

        //按评论数量由高到低排名
        $comment = DB::table('films')
        ->leftjoin('film_atts','films.fid','=','film_atts.fid')
        //->leftjoin('areas','films.area_id','=','areas.area_id')
        ->orderBy('count_uid','desc')->paginate(10);


        //按拍摄年代由高到低排名
        $period = DB::table('films')
        ->leftjoin('film_atts','films.fid','=','film_atts.fid')
        //->leftjoin('areas','films.area_id','=','areas.area_id')
        ->orderBy('period','desc')->paginate(10);

       //按最近更新由高到低排名
        $recent = DB::table('films')
        ->leftjoin('film_atts','films.fid','=','film_atts.fid')
       // ->leftjoin('areas','films.area_id','=','areas.area_id')
        ->orderBy('films.fid','desc')->paginate(10);
        //显示页面导航
        $nave = DB::table('film_types')->get();
        $areas = DB::table('areas')->get();

        //获取信息输出到模板
        return view('Home/list',
            ['slist' => $sea_list,
            'score'  => $score,
            'ftype'  => $nave,
            'area'   => $areas,
            'comment'=> $comment,
            'period' => $period,
            'recent' => $recent,
            'infor'=>$sea]);
        
    }


    public function redirected(){
        return 'ddd';
    }







    ///按分类显示电影类型
    public function find_type($fid){
        //按电影类型分类查询
        $each_type = DB::table('films')
        
        ->leftjoin('film_atts','films.fid','=','film_atts.fid')
       
        ->where('type_id',$fid)->paginate();
        //**查出影片地区名称轮回并输出到模板
        $areas = DB::table('areas')->get();
        $fty = DB::table('film_types')->where('type_id',$fid)->first();
        //获取当前类型并按分数高低输入到模板中‘您可能喜欢的区域’
         $may_like = DB::table('films')
        
        ->leftjoin('film_atts','films.fid','=','film_atts.fid')
      
        ->where('films.type_id',$fid)
        ->orderBy('score','desc')
        ->get();
        $nave = DB::table('film_types')->get();
        //返回信息输出到模板;
        return view('Home/showtype',['ftyped'=>$each_type,'fty'=>$fty,'ftype'=>$nave,'area'=>$areas,'like'=>$may_like]);
    }






    //按影片地区分类
    public function showarea($area_id){
        //循环打印地区信息到模板
        $areas = DB::table('areas')->get();
        $endm = DB::table('films')
        ->leftjoin('film_atts','films.fid','=','film_atts.fid')
        ->where('is_rec',1)->get();
        //影片按地区分类查询
        $getarea = DB::table('films')
        ->leftjoin('film_atts','films.fid','=','film_atts.fid')
        ->where('area_id',$area_id)->paginate();

        $title_area = DB::table('areas')->where('area_id',$area_id)->first();
        //返回信息输出到模板;
        return view('Home/showarea', ['area'=>$areas ,'getarea'=>$getarea,'ftitle'=>$title_area,'endm'=>$endm]);
    }



    //进入影片详情页面，准备播放
    public function pre_display(){
        return view('Home/single');
    }




}
